function res = kdatest(stego, cover, ntrain, ntest, loop, verbose, ktype)
if nargin < 6
    verbose = 1;
end
if nargin < 7
    ktype = 'Gaussian';
end
[s1, h1] = size(stego);
[s2, h2] = size(cover);
ntrain = ntrain / 2;
ntest = ntest / 2;
if (ntrain+ntest > s1) || (ntrain + ntest > s2)
    error('number of training and testing samples must less than .');
end
if (h1 ~= h2) || (s1 ~= s2)
    error('dimension of stego / cover does not match.');
end


res = struct();
res.MEAN_ACC = 0;
res.acc = zeros(loop, 1);
res.train_time = zeros(loop, 1);

options = struct('KernelType', ktype, 't', 1);
for i = 1:loop
    if verbose
        fprintf('round %d:\n',i);
    end
    p = randperm(s1);
    
    trainset = [stego(p(1:ntrain),:);cover(p(1:ntrain),:)];
    trainlbl = [ones(ntrain, 1);zeros(ntrain, 1)];

    t1 = cputime;
    [eigvector, eigvalue, Ktrain] = KDA(options, trainlbl, trainset);
    res.train_time(i) = cputime - t1;
    
    decv = Ktrain*eigvector;
    vstego = mean(decv(1:ntrain));
    vcover = mean(decv(ntrain+1:end));
    vmean = (vstego + vcover) / 2;
    ab = (vstego >= vcover);
    % just check if acc in train set is >= 0.5
    val = (decv-vmean) >= 0;
    if ~ab
        val = ~val;
    end
    train_acc = sum(val == trainlbl) / ntrain / 2;
    assert(train_acc >= 0.5);
    model = struct('eigvector', eigvector, 'eigvalue', eigvalue, ...
        'options', options, 'mean', vmean, 'ab', ab, ...
        'mean_cover', vcover, 'mean_stego', vstego, ...
        'train_acc', train_acc);
    clear ab vmean vstego vcover val decv train_acc
    
    testset = [stego(p(ntrain+1:ntrain+ntest),:);cover(p(ntrain+1:ntrain+ntest),:)];
    Ktest = constructKernel(testset, trainset, options);
    decv = Ktest*eigvector - model.mean;
    
    testlbl = [ones(ntest,1);zeros(ntest,1)];
    val = decv >= 0;
    if ~model.ab
        val = ~val;
    end
    acc = sum(val == testlbl) / ntest / 2;
    
    if verbose
        fprintf('acc = %g\n',acc);
        fprintf('time = %g\n',res.train_time(i));
    end
    res.acc(i) = acc;
end
res.MEAN_ACC = mean(res.acc);
res.MEAN_TRAIN_TIME = mean(res.train_time);
if verbose
    disp(res)
end
end
